﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ExtremeSwank.Authentication.OpenID.Persistence
{
    /// <summary>
    /// Provides session persistence to OpenID functions using the ASP.NET Session object.
    /// </summary>
    public class SessionSessionManager : ISessionPersistence
    {

        #region ISessionPersistence Members

        /// <summary>
        /// Gets or sets whether or not to force the use of stateless mode.
        /// </summary>
        public bool EnforceStatelessMode
        {
            get
            {
                if (SessionObjectPersister.Get("ForceDumb") == null) { return false; }
                return (bool)SessionObjectPersister.Get("ForceDumb");
            }
            set
            {
                SessionObjectPersister.Set("ForceDumb", value);
            }
        }
        /// <summary>
        /// Gets or sets the nonce value used to protect against replay attacks.
        /// </summary>
        public int Cnonce
        {
            get
            {
                if (SessionObjectPersister.Get("AllowLogin") == null)
                {
                    return -1;
                }
                return (int)SessionObjectPersister.Get("AllowLogin");
            }
            set { SessionObjectPersister.Set("AllowLogin", value); }
        }

        /// <summary>
        /// Gets or sets whether or not a delegate identity was discovered
        /// during OpenID discovery.
        /// </summary>
        public bool DiscoveredDelegate
        {
            get
            {
                if (SessionObjectPersister.Get("DiscoveredDelegate") == null) { return false; }
                return (bool)SessionObjectPersister.Get("DiscoveredDelegate");
            }
            set { SessionObjectPersister.Set("DiscoveredDelegate", value); }
        }

        #endregion
    }
}
